package com.feng.zhihao.apigeteway.gateway.bean.impl.GENERATION_RULE;

import org.springframework.stereotype.Component;

import com.feng.zhihao.apigeteway.entity.InterfaceFieldGenerationRule;
import com.feng.zhihao.apigeteway.entity.InterfaceFieldInfo;
import com.feng.zhihao.apigeteway.exception.ExceptionMessage;
import com.feng.zhihao.apigeteway.exception.GetewayException;
import com.feng.zhihao.apigeteway.gateway.ReqContext;
import com.feng.zhihao.apigeteway.gateway.bean.GENERATION_RULE;

import ognl.Ognl;
import ognl.OgnlException;

@Component("GENERATION_RULE_OGNL")
public class GENERATION_RULE_OGNL implements GENERATION_RULE{

	@Override
	public Object generationValue(InterfaceFieldInfo interfaceFieldInfo, InterfaceFieldGenerationRule rule, ReqContext reqContext) {
		try {
			return Ognl.getValue(rule.getOgnl(), reqContext);
		} catch (OgnlException e) {
			throw new GetewayException(e,ExceptionMessage.GENERATION_RULE_OGNL_EXCEPTION,interfaceFieldInfo.getInterfaceFieldName(),rule.getOgnl(),rule.getGenerationRuleId());
		}
		
	}

}
